<html>
<head>
	<title>Tests for JU.validate</title>
	
	<script type="text/javascript" src="jsunit/app/jsUnitCore.js"></script>
	<script type="text/javascript" src="../src/janutils.js"></script>
	<script type="text/javascript" src="../src/validate.js"></script>
	
	<script type="text/javascript">
	
	//--------------------------------------------------------------------------
	// Tests with null parameters
	//--------------------------------------------------------------------------
	
	/*
	 * Tests empty() with a null parameter
	 */
	function testEmptyWithNull() {
		assertTrue(JU.validate.empty(null));
	}
	
	/*
	 * Tests blank() with a null parameter
	 */
	function testBlankWithNull() {
		assertTrue(JU.validate.blank(null));
	}
	
	/*
	 * Tests digits() with a null parameter
	 */
	function testDigitsWithNull() {
		assertFalse(JU.validate.digits(null));
	}
	
	/*
	 * Tests integer() with a null parameter
	 */
	function testIntegerWithNull() {
		assertFalse(JU.validate.integer(null));
	}
	
	/*
	 * Tests decimal() with a null parameter
	 */
	function testDecimalWithNull() {
		assertFalse(JU.validate.decimal(null));
	}
	
	/*
	 * Tests date() with null parameters
	 */
	function testDateWithNull() {
		assertFalse(JU.validate.date(null, null));
	}
	
	/*
	 * Tests date() with a null date and a valid format
	 */
	function testDateWithDateNull() {
		assertFalse(JU.validate.date(null, 'dd/MM/yyyy'));
	}
	
	/*
	 * Tests date() with a valid date and a null format
	 */
	function testDateWithFormatNull() {
		assertFalse(JU.validate.date('20/03/1982', null));
	}
	
	/*
	 * Tests email() with a null parameter
	 */
	function testEmailWithNull() {
		assertFalse(JU.validate.email(null));
	}
	
	//--------------------------------------------------------------------------
	// Tests with undefined parameters
	//--------------------------------------------------------------------------
	
	/*
	 * Tests empty() with a undefined parameter
	 */
	function testEmptyWithUndefined() {
		assertTrue(JU.validate.empty(undefined));
	}
	
	/*
	 * Tests blank() with a undefined parameter
	 */
	function testBlankWithUndefined() {
		assertTrue(JU.validate.blank(undefined));
	}
	
	/*
	 * Tests digits() with a undefined parameter
	 */
	function testDigitsWithUndefined() {
		assertFalse(JU.validate.digits(undefined));
	}
	
	/*
	 * Tests integer() with a undefined parameter
	 */
	function testIntegerWithUndefined() {
		assertFalse(JU.validate.integer(undefined));
	}
	
	/*
	 * Tests decimal() with a undefined parameter
	 */
	function testDecimalWithUndefined() {
		assertFalse(JU.validate.decimal(undefined));
	}
	
	/*
	 * Tests date() with a null parameters
	 */
	function testDecimalWithUndefined() {
		assertFalse(JU.validate.date(null, null));
	}
	
	/*
	 * Tests email() with a undefined parameter
	 */
	function testEmailWithUndefined() {
		assertFalse(JU.validate.email(undefined));
	}
	
	//--------------------------------------------------------------------------
	// Tests with empty parameters
	//--------------------------------------------------------------------------
	
	/*
	 * Tests empty() with an empty string parameter
	 */
	function testEmptyWithEmptyString() {
		assertTrue(JU.validate.empty(''));
	}
	
	/*
	 * Tests blank() with an empty string parameter
	 */
	function testBlankWithEmptyString() {
		assertTrue(JU.validate.blank(''));
	}
	
	/*
	 * Tests digits() with an empty string parameter
	 */
	function testDigitsWithEmptyString() {
		assertFalse(JU.validate.digits(''));
	}
	
	/*
	 * Tests integer() with an empty string parameter
	 */
	function testIntegerWithEmptyString() {
		assertFalse(JU.validate.integer(''));
	}
	
	/*
	 * Tests decimal() with an empty string parameter
	 */
	function testDecimalWithEmptyString() {
		assertFalse(JU.validate.decimal(''));
	}
	
	/*
	 * Tests date() with empty string parameters
	 */
	function testDecimalWithEmptyString() {
		assertFalse(JU.validate.date('', ''));
	}
	
	/*
	 * Tests email() with a empty parameter
	 */
	function testEmailWithEmptyString() {
		assertFalse(JU.validate.email(''));
	}
	
	//--------------------------------------------------------------------------
	// Tests with correct parameters
	//--------------------------------------------------------------------------
	
	/*
	 * Tests empty() with an expected input
	 */
	function testEmpty() {
		assertTrue(JU.validate.empty(''));
	}
	
	/*
	 * Tests blank() with an expected input
	 */
	function testBlank() {
		assertTrue(JU.validate.blank('      '));
	}
	
	/*
	 * Tests digits() with an expected input
	 */
	function testDigits() {
		assertTrue(JU.validate.digits('0123456789'));
	}
	
	/*
	 * Tests integer() with an positive integer
	 */
	function testIntegerPositive() {
		assertTrue(JU.validate.integer('123456789'));
	}
	
	/*
	 * Tests integer() with a negative integer
	 */
	function testIntegerNegative() {
		assertTrue(JU.validate.integer('-123456789'));
	}
	
	/*
	 * Tests integer() with an positive integer starting with zero
	 */
	function testIntegerPositiveStartingWithZero() {
		assertTrue(JU.validate.integer('0123456789'));
	}
	
	/*
	 * Tests integer() with a negative integer starting with zero
	 */
	function testIntegerNegativeStartingWithZero() {
		assertTrue(JU.validate.integer('-0123456789'));
	}
	
	/*
	 * Tests integer() with a zero
	 */
	function testIntegerZero() {
		assertTrue(JU.validate.integer('0'));
	}
	
	/*
	 * Tests integer() with zeroes
	 */
	function testIntegerZeroes() {
		assertTrue(JU.validate.integer('000000000'));
	}
	
	/*
	 * Tests integer() with a minus zero
	 */
	function testIntegerWithMinusZero() {
		assertTrue(JU.validate.integer('-0'));
	}
	
	/*
	 * Tests integer() with a minus zero
	 */
	function testIntegerWithMinusZeroes() {
		assertTrue(JU.validate.integer('-00000000'));
	}
	
	/*
	 * Tests decimal() with a positive number
	 */
	function testDecimalPositive() {
		assertTrue(JU.validate.decimal('1234.56789'));
	}
	
	/*
	 * Tests decimal() with a negative number
	 */
	function testDecimalNegative() {
		assertTrue(JU.validate.decimal('-1234.56789'));
	}
	
	/*
	 * Tests decimal() with a positive integer starting with zero
	 */
	function testDecimalPositiveStartingWithZero() {
		assertTrue(JU.validate.decimal('01234.56789'));
	}
	
	/*
	 * Tests decimal() with a negative integer starting with zero
	 */
	function testDecimalNegativeStartingWithZero() {
		assertTrue(JU.validate.decimal('-01234.56789'));
	}
	
	/*
	 * Tests decimal() with a positive integer
	 */
	function testDecimalWithPositiveInteger() {
		assertTrue(JU.validate.decimal('123456789'));
	}
	
	/*
	 * Tests decimal() with a negative integer
	 */
	function testDecimalWithNegativeInteger() {
		assertTrue(JU.validate.decimal('-123456789'));
	}
	
	/*
	 * Tests decimal() with a positive integer starting with zero
	 */
	function testDecimalWithPositiveIntegerStartingWithZero() {
		assertTrue(JU.validate.decimal('0123456789'));
	}
	
	/*
	 * Tests decimal() with a negative integer starting with zero
	 */
	function testDecimalWithNegativeIntegerStartingWithZero() {
		assertTrue(JU.validate.decimal('-0123456789'));
	}
	
	/*
	 * Tests decimal() with a zero
	 */
	function testDecimalZero() {
		assertTrue(JU.validate.decimal('0'));
	}
	
	/*
	 * Tests decimal() with zeroes
	 */
	function testDecimalZeroes() {
		assertTrue(JU.validate.decimal('000000000'));
	}
	
	/*
	 * Tests decimal() with a minus zero
	 */
	function testDecimalWithMinusZero() {
		assertTrue(JU.validate.decimal('-0'));
	}
	
	/*
	 * Tests decimal() with a minus zero
	 */
	function testDecimalWithMinusZeroes() {
		assertTrue(JU.validate.decimal('-00000000'));
	}
	
	/*
	 * Tests decimal() with a minus zero point zero
	 */
	function testDecimalWithMinusZeroPointZero() {
		assertTrue(JU.validate.decimal('-0.0'));
	}
	
	/*
	 * Tests decimal() with a minus zeroes point zero
	 */
	function testDecimalWithMinusZeroes() {
		assertTrue(JU.validate.decimal('-00000000.0'));
	}
	
	/*
	 * Tests date() with a valid date in dd/MM/yyyy format
	 */
	function testDate() {
		assertTrue(JU.validate.date('20/03/1982', 'dd/MM/yyyy'));
	}
	
	/*
	 * Tests date() with a valid date in MM/dd/yyyy format
	 */
	function testDateMMddyyyy() {
		assertTrue(JU.validate.date('03/20/1982', 'MM/dd/yyyy'));
	}
	
	/*
	 * Tests date() with a valid date in yyyy/MM/dd format
	 */
	function testDateyyyyMMdd() {
		assertTrue(JU.validate.date('1982/03/20', 'yyyy/MM/dd'));
	}
	
	/*
	 * Tests date() with a valid date in yyyy/dd/MM format
	 */
	function testDateyyyyddMM() {
		assertTrue(JU.validate.date('1982/20/03', 'yyyy/dd/MM'));
	}
	
	/*
	 * Tests email() with a valid email
	 */
	function testEmail() {
		assertTrue(JU.validate.email('janutils@gmail.com'));
	}
	
	/*
	 * Tests email() with a valid email that contains different sepparators
	 */
	function testEmailWithSeparators() {
		assertTrue(JU.validate.email('janutil.js-0.1_beta@my.test.com'));
	}

	//--------------------------------------------------------------------------
	// Tests with incorrect parameters
	//--------------------------------------------------------------------------
	
	/*
	 * Tests empty() with an space
	 */
	function testEmptyWithSpace() {
		assertFalse(JU.validate.empty(' '));
	}
	
	/*
	 * Tests empty() with an alphabetic parameter
	 */
	function testEmptyWithAlpha() {
		assertFalse(JU.validate.empty('JanUtils'));
	}
	
	/*
	 * Tests blank() with an alphabetic parameter
	 */
	function testBlankWithAlpha() {
		assertFalse(JU.validate.blank('JanUtils'));
	}
	
	/*
	 * Tests blank() with an string that starts with a space
	 */
	function testBlankWithStartSpace() {
		assertFalse(JU.validate.blank(' a'));
	}
	
	/*
	 * Tests blank() with an string that finishes with a space
	 */
	function testBlankWithFinishSpace() {
		assertFalse(JU.validate.blank('a '));
	}
	
	/*
	 * Tests integer() with an alphabetic parameter
	 */
	function testIntegerWithAlpha() {
		assertFalse(JU.validate.integer('JanUtils'));
	}
	
	/*
	 * Tests integer() with a minus sign
	 */
	function testIntegerWithMinus() {
		assertFalse(JU.validate.integer('-'));
	}
	
	/*
	 * Tests integer() with a double minus sign
	 */
	function testIntegerWithDoubleMinus() {
		assertFalse(JU.validate.integer('--'));
	}
	
	/*
	 * Tests decimal() with an alphabetic parameter
	 */
	function testDecimalWithAlpha() {
		assertFalse(JU.validate.decimal('JanUtils'));
	}
	
	/*
	 * Tests decimal() with a minus sign
	 */
	function testDecimalWithMinus() {
		assertFalse(JU.validate.decimal('-'));
	}
	
	/*
	 * Tests decimal() with a double minus sign
	 */
	function testDecimalWithDoubleMinus() {
		assertFalse(JU.validate.decimal('--'));
	}
	
	/*
	 * Tests digits() with an alphabetic parameter
	 */
	function testDigitsWithAlpha() {
		assertFalse(JU.validate.digits('JanUtils'));
	}
	
	/*
	 * Tests digits() with an string that starts with a space
	 */
	function testDigitsWithStartSpace() {
		assertFalse(JU.validate.digits(' 9'));
	}
	
	/*
	 * Tests digits() with an string that finishes with a space
	 */
	function testDigitsWithFinishSpace() {
		assertFalse(JU.validate.digits('9 '));
	}
	
	/*
	 * Tests digits() with an string that starts with a space
	 */
	function testDigitsWithStartSpace() {
		assertFalse(JU.validate.digits(' 9'));
	}
	
	/*
	 * Tests digits() with an string that finishes with a space
	 */
	function testDigitsWithFinishSpace() {
		assertFalse(JU.validate.digits('9 '));
	}
	
	/*
	 * Tests date() with an space and a valid format
	 */
	function testDateWithSpace() {
		assertFalse(JU.validate.date(' ', 'dd/MM/yyyy'));
	}
	
	/*
	 * Tests date() with an alphabetic string and a valid format
	 */
	function testDateWithAlpha() {
		assertFalse(JU.validate.date('abcdef', 'dd/MM/yyyy'));
	}
	
	/*
	 * Tests date() with a numric string and a valid format
	 */
	function testDateWithNumbers() {
		assertFalse(JU.validate.date('12345', 'dd/MM/yyyy'));
	}
	
	/*
	 * Tests date() with a date string that starts with a space and a valid format
	 */
	function testDateWithStartSpace() {
		assertFalse(JU.validate.date(' 20/03/1982', 'dd/MM/yyyy'));
	}
	
	/*
	 * Tests date() with a date string that finishes with a space and a valid format
	 */
	function testDateWithFinishSpace() {
		assertFalse(JU.validate.date('20/03/1982 ', 'dd/MM/yyyy'));
	}
	
	/*
	 * Tests date() with an invalid date and a valid format
	 */
	function testDateInvalid() {
		assertFalse(JU.validate.date('03/20/1982', 'dd/MM/yyyy'));
	}
	
	/*
	 * Tests date() with february 29 in a no leap year and a valid format
	 */
	function testDateInvalidNoLeap() {
		assertFalse(JU.validate.date('29/02/2009', 'dd/MM/yyyy'));
	}
	
	/*
	 * Tests date() with a valid date and spaces as format
	 */
	function testDateWithSpaceFormat() {
		assertFalse(JU.validate.date('20/03/1982', '   '));
	}
	
	/*
	 * Tests date() with a valid date and an alphabetic format
	 */
	function testDateWithAlphaFormat() {
		assertFalse(JU.validate.date('20/03/1982', 'abcdef'));
	}
	
	/*
	 * Tests date() with a valid date and a numeric format
	 */
	function testDateWithNumbersFormat() {
		assertFalse(JU.validate.date('20/03/1982', '1234567'));
	}
	
	/*
	 * Tests date() with a valid date and a format that starts with a space
	 */
	function testDateWithStartSpaceFormat() {
		assertFalse(JU.validate.date('20/03/1982', ' dd/MM/yyyy'));
	}
	
	/*
	 * Tests date() with a valid date and a format that finishes with a space
	 */
	function testDateWithFinishSpaceFormat() {
		assertFalse(JU.validate.date('20/03/1982', 'dd/MM/yyyy '));
	}
	
	/*
	 * Tests date() with a format that repeats the day part
	 */
	function testDateWithRepeatedFormat() {
		assertFalse(JU.validate.date('20/03/1982', 'dd/dd/yyyy'));
	}
	
	/*
	 * Tests email() with an space
	 */
	function testEmailWithSpace() {
		assertFalse(JU.validate.email(' '));
	}
	
	/*
	 * Tests email() with an alphabetic parameter
	 */
	function testEmailWithAlpha() {
		assertFalse(JU.validate.email('JanUtils'));
	}
	
	/*
	 * Tests email() with a numeric parameter
	 */
	function testEmailWithNumbers() {
		assertFalse(JU.validate.email('1234567890'));
	}
	
	/*
	 * Tests email() with a email without the left part
	 */
	function testEmailWithoutLeft() {
		assertFalse(JU.validate.email('@gmail.com'));
	}
	
	/*
	 * Tests email() with a email without the right part
	 */
	function testEmailWithoutRight() {
		assertFalse(JU.validate.email('JanUtils'));
	}
	
	/*
	 * Tests email() with a email with spaces to the left
	 */
	function testEmailWithSpacesLeft() {
		assertFalse(JU.validate.email(' janutils@gmail.com'));
	}
	
	/*
	 * Tests email() with a email with spaces to the right
	 */
	function testEmailWithSpacesRight() {
		assertFalse(JU.validate.email('janutils@gmail.com '));
	}
	
	</script>
</head>
<body>
</body>
</html>